home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
mig
/
RCS
/
MigHostCache.c,v
< prev
next >
Wrap
Text File
|
1990-09-24
|
4KB
|
175 lines
head 2.1;
branch ;
access ;
symbols no-auto-remigrate:2.0 installed:2.0;
locks ; strict;
comment @ * @;
2.1
date 90.09.24.14.46.46; author douglis; state Exp;
branches ;
next 2.0;
2.0
date 90.03.10.13.12.31; author douglis; state Stable;
branches ;
next 1.1;
1.1
date 90.02.16.14.26.51; author douglis; state Exp;
branches ;
next ;
desc
@Internal routine to manage the cache of available hosts.
@
2.1
log
@added callback flag to MigHostCache to make it easier to flag all hosts as reclaimed after error
@
text
@/*
* MigHostCache.c --
*
* Internal routine to manage the cache of available hosts.
*
* Copyright 1990 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/lib/c/mig/RCS/MigHostCache.c,v 2.0 90/03/10 13:12:31 douglis Stable Locker: douglis $ SPRITE (Berkeley)";
#endif /* not lint */
#include <sprite.h>
#include <hash.h>
#include <stdlib.h>
#include <mig.h>
#include "migInt.h"
static Hash_Table table;
/*
*----------------------------------------------------------------------
*
* MigHostCache --
*
* Add, remove, or verify an entry in the host cache.
*
* Results:
* TRUE if the host is in the cache at the start of the operation,
* FALSE otherwise.
*
* Side effects:
* Hash table is updated.
*
*----------------------------------------------------------------------
*/
int
MigHostCache(hostID, op, callback)
int hostID; /* Host to operate on. */
MigCacheOp op; /* Operation to perform. */
int callback; /* Whether to invoke callback function */
{
static int init = 0;
Hash_Entry *entryPtr; /* Entry in hash table. */
int found;
if (!init) {
if (op == MIG_CACHE_REMOVE_ALL) {
return(0);
}
Hash_InitTable(&table, 0, HASH_ONE_WORD_KEYS);
init = 1;
}
switch (op) {
case MIG_CACHE_ADD: {
/*
* Create the entry if it doesn't exist. Sets third arg
* to TRUE if it creates it, meaning it wasn't found, so
* we have to negate it.
*/
entryPtr = Hash_CreateEntry(&table, (Address) hostID, &found);
found = !found;
Hash_SetValue(entryPtr, (ClientData) hostID);
break;
}
case MIG_CACHE_VERIFY:
case MIG_CACHE_REMOVE: {
entryPtr = Hash_FindEntry(&table, (Address) hostID);
found = (entryPtr != (Hash_Entry *) NULL);
if (op == MIG_CACHE_REMOVE && found) {
Hash_DeleteEntry(&table, entryPtr);
}
if (callback && (migCallBackPtr != NULL)) {
(*migCallBackPtr)(hostID);
}
break;
}
case MIG_CACHE_REMOVE_ALL: {
if (callback && (migCallBackPtr != NULL)) {
Hash_Search search;
for (entryPtr = Hash_EnumFirst(&table, &search);
entryPtr != NULL; entryPtr = Hash_EnumNext(&search)) {
hostID = (int) Hash_GetValue(entryPtr);
(*migCallBackPtr)(hostID);
}
}
Hash_DeleteTable(&table);
init = 0;
return(0);
}
default: {
return(0);
}
}
return(found);
}
@
2.0
log
@Changing version numbers.
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: /sprite/src/lib/c/mig/RCS/MigHostCache.c,v 1.1 90/02/16 14:26:51 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
d47 1
a47 1
MigHostCache(hostID, op)
d50 1
d57 3
d73 1
d83 4
d90 8
d108 1
@
1.1
log
@Initial revision
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: /user2/douglis/pdev_mig/mig_p/RCS/MigHostCache.c,v 1.1 90/02/08 20:22:24 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
@